package com.example.boss.pinkdiary;

/**
 * Created by 打好boss on 2018/6/12.
 */


import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.boss.db.gen.diaryTag;

import java.util.List;


public class writeDialogAdapter extends RecyclerView.Adapter<writeDialogAdapter.mViewHolder> {
    private List<diaryTag> mDataList;
    private Context context;
    public interface ItemClickListener{
        void onItemClick(View view,int position);
        boolean onItemLongClick(View view,int position);
    }
    public ItemClickListener mListener;
    public void setOnItemClickListener(ItemClickListener listener){
        this.mListener=listener;
    }

    public writeDialogAdapter(List<diaryTag> list) {
        mDataList = list;

    }
    @Override
    public int getItemCount() {
        // 返回数据集合大小
        return mDataList == null ? 0 : mDataList.size();
    }
    @Override
    public void onBindViewHolder(final mViewHolder holder, final int position) {
        TextView tv = holder.mTvTitle;
        if(!mDataList.get(position).getTag().equals("全部")) tv.setText(mDataList.get(position).getTag());
        else tv.setVisibility(View.GONE);
        View itemView = ((LinearLayout) holder.itemView).getChildAt(0);

        if(mListener!=null){
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int position = holder.getLayoutPosition();
                    mListener.onItemClick(holder.itemView, position);
                }
            });
            itemView.setOnLongClickListener(new View.OnLongClickListener(){
                @Override
                public boolean onLongClick(View v){
                    int position = holder.getLayoutPosition();
                    mListener.onItemLongClick(holder.itemView, position);
                    return true;
                }
            });
        }
    }

    @Override
    public mViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new mViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.write_dialog_item, parent, false));
    }
    public class mViewHolder extends RecyclerView.ViewHolder {
        private TextView mTvTitle;

        public mViewHolder(View itemView) {
            super(itemView);
            mTvTitle = (TextView) itemView.findViewById(R.id.item_tv);

        }
    }



}
